//
//  CSMyOrderConfirmingCell.m
//  ProjectforHDX
//
//  Created by wusiping on 16/8/9.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "CSMyOrderConfirmingCell.h"


#define TOPMARGIN 5
#define LEFTEMARGIN 10
#define LABHEIGHT 20


#define TICK   NSDate *startTime = [NSDate date];
#define TOCK   NSLog(@"Time: %f", -[startTime timeIntervalSinceNow]);


@interface CSMyOrderConfirmingCell()



{
    NSInteger state;
}

@property (nonatomic, copy) DetailTouchBlock touchBlock;
@property (nonatomic, copy) RMADetailTouchBlock RMATouchBlock;
@property (nonatomic, strong) NSDictionary * orderStatusDict;


@end

@implementation CSMyOrderConfirmingCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        self.cellContentView=[[UIView alloc] init];
        [self.cellContentView setClipsToBounds:YES];
        [self.cellContentView setBackgroundColor:[UtilCheck hexStringToColor:@"ffffff" alpha:1]];
        [self addSubview:self.cellContentView];
        
        //故障件数  一线备件数
        self.NumOfGoodsLab =[[RZCustomLable alloc] init ];
        self.NumOfGoodsLab.font = CustomFont(14);
        self.NumOfGoodsLab.textColor = SYSTEM_COLOR;
        self.NumOfGoodsLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.NumOfGoodsLab];
        
        //序号
        self.NumLab =[[RZCustomLable alloc] init ];
        self.NumLab.textColor = [UIColor whiteColor];
        self.NumLab.backgroundColor = SYSTEM_COLOR;
        self.NumLab.textAlignment = NSTextAlignmentCenter;
        self.NumLab.font = CustomFont(14);
        self.NumLab.layer.cornerRadius = LABHEIGHT/2.0;
        self.NumLab.clipsToBounds = YES;
        [self.cellContentView addSubview:self.NumLab];
        
        //标题，故障件信息
        self.titleLabel =[[RZCustomLable alloc] init ];
        self.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        self.titleLabel.textColor = [UtilCheck hexStringToColor:@"858e99" alpha:1];
        self.titleLabel.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.titleLabel];
        
        
        //RMA
        self.RMALab =[[HideTextLable alloc] init ];
        self.RMALab.font = CustomFont(13);
        self.RMALab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.RMALab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.RMALab];
        
        //故障件名称
        self.nameLab =[[RZCustomLable alloc] init ];
        self.nameLab.font = CustomFont(13);
        self.nameLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.nameLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.nameLab];
        
        
        //板件号
        self.codeLab =[[RZCustomLable alloc] init ];
        self.codeLab.font = CustomFont(13);
        self.codeLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.codeLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.codeLab];
        
        //提示
        self.promptBtn = [[RZCustomButtom alloc]init];
        self.promptBtn.userInteractionEnabled = NO;
        [self.promptBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.promptBtn setBackgroundImage:BDFILEIMAGENAEM(@"Order/orderDetailPromptGreen") forState:UIControlStateNormal];
        self.promptBtn.titleLabel.font = CustomFont(13);
        [self.cellContentView addSubview:self.promptBtn];
        //版本号
        self.vsLab =[[RZCustomLable alloc] init ];
        self.vsLab.font = CustomFont(13);
        self.vsLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.vsLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.vsLab];
        
        //序列号
        self.snLab =[[RZCustomLable alloc] init ];
        self.snLab.font = CustomFont(13);
        self.snLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.snLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.snLab];
        
        
        //数量
        self.countLab =[[RZCustomLable alloc] init ];
        self.countLab.font = CustomFont(13);
        self.countLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.countLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.countLab];
        
        
        //故障描述
        self.troubleDescribleLab =[[HideTextLable alloc] init ];
        self.troubleDescribleLab.font = CustomFont(13);
        self.troubleDescribleLab.textColor = [UIColor blueColor];
        self.troubleDescribleLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.troubleDescribleLab];
        
        //站名
        self.stationNameLab =[[RZCustomLable alloc] init ];
        self.stationNameLab.font = CustomFont(13);
        self.stationNameLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.stationNameLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.stationNameLab];
        
        //siteID
        self.siteIDLab =[[RZCustomLable alloc] init ];
        self.siteIDLab.font = CustomFont(13);
        self.siteIDLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.siteIDLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.siteIDLab];
        
        
        //副标题，使用了一线备件名称
        self.subTitleLab =[[RZCustomLable alloc] init ];
        self.subTitleLab.font = [UIFont fontWithName:@"Helvetica-Bold" size:12];
        self.subTitleLab.textColor = [UtilCheck hexStringToColor:@"1a57be" alpha:1];
        self.subTitleLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.subTitleLab];
        
        //板件名称
        self.subNameLab =[[RZCustomLable alloc] init ];
        self.subNameLab.font = CustomFont(13);
        self.subNameLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.subNameLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.subNameLab];
        
        //板件号
        self.subCodeLab =[[RZCustomLable alloc] init ];
        self.subCodeLab.font = CustomFont(13);
        self.subCodeLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.subCodeLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.subCodeLab];
        
        //版本号
        self.subVsLab =[[RZCustomLable alloc] init ];
        self.subVsLab.font = CustomFont(13);
        self.subVsLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.subVsLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.subVsLab];
        
        //板件序列号
        self.subSnLab =[[RZCustomLable alloc] init ];
        self.subSnLab.font = CustomFont(13);
        self.subSnLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.subSnLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.subSnLab];
        
        //分隔线
        self.separateLab =[[RZCustomLable alloc] init ];
        self.separateLab.font = CustomFont(13);
        // self.separateLab.textColor = [UIColor grayColor];
        self.separateLab.textAlignment = NSTextAlignmentLeft;
        self.separateLab.backgroundColor = [UtilCheck hexStringToColor:@"e5e5e5" alpha:1];
        [self.cellContentView addSubview:self.separateLab];
        
        //分隔线竖着的
        self.uprightSeparateLab =[[RZCustomLable alloc] init ];
        self.uprightSeparateLab.font = CustomFont(13);
        // self.uprightSeparateLab.textColor = [UIColor grayColor];
        self.uprightSeparateLab.textAlignment = NSTextAlignmentLeft;
        self.uprightSeparateLab.backgroundColor = [UtilCheck hexStringToColor:@"e5e5e5" alpha:1];
        [self.cellContentView addSubview:self.uprightSeparateLab];
        
        
        
        //是否同时到达
        self.isSameTimeLab =[[RZCustomLable alloc] init ];
        self.isSameTimeLab.font = CustomFont(13);
        self.isSameTimeLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.isSameTimeLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.isSameTimeLab];
        
        //备注
        self.remarkLab =[[RZCustomLable alloc] init ];
        self.remarkLab.font = CustomFont(13);
        self.remarkLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.remarkLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.remarkLab];
        
        
        
        //标题，好件信息
        self.goodTitleLab =[[RZCustomLable alloc] init ];
        self.goodTitleLab.textColor = [UtilCheck hexStringToColor:@"1a57be" alpha:1];
        self.goodTitleLab.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        self.goodTitleLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.goodTitleLab];
        
        
        //好件名称
        self.goodNameLab =[[RZCustomLable alloc] init ];
        self.goodNameLab.font = CustomFont(13);
        self.goodNameLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.goodNameLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.goodNameLab];
        
        //好件板件号
        self.goodCodeLab =[[RZCustomLable alloc] init ];
        self.goodCodeLab.font = CustomFont(13);
        self.goodCodeLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.goodCodeLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.goodCodeLab];
        
        //好件版本号
        self.goodVsLab =[[RZCustomLable alloc] init ];
        self.goodVsLab.font = CustomFont(13);
        self.goodVsLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.goodVsLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.goodVsLab];
        //  y2285173409
        //好件数量
        self.goodNumber=[[RZCustomLable alloc]init];
        self.goodNumber.font= CustomFont(13);
        self.goodNumber.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.goodNumber.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.goodNumber];
        
        //好件序列号
        self.goodSnLab =[[RZCustomLable alloc] init ];
        self.goodSnLab.font = CustomFont(13);
        self.goodSnLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.goodSnLab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.goodSnLab];
        [self.cellContentView bringSubviewToFront:self.promptBtn];
        NSLog(@"我们%@",_orderStatusDict);
        
        
    }
    return self;
}

- (void)setData:(NSDictionary *)data andOrderStatus:(NSDictionary *)orderStatusDict {
    
    if (_data != data) {
        _data=data;
        _orderStatusDict = [[NSDictionary alloc]initWithDictionary:orderStatusDict];
        NSInteger row = self.row;
        NSString *operationString = _orderStatusDict[@"operation"];
        
        NSString *isPutInStorageString = _data[@"faultParts"][row][@"faultPart"][@"isPutInStorage"];
        
        NSLog(@"row: %ld isPutInStorageString：%@",self.row,isPutInStorageString);
        
        if ([isPutInStorageString isEqualToString:@"0"] && ([operationString rangeOfString:@"10"].location != NSNotFound)) {
            // 取件提醒按钮
            state = 0;
            self.takeDic = [[NSMutableDictionary alloc]init];
            self.takeButton = [RZCustomButtom buttonWithType:UIButtonTypeCustom];
            [self.takeButton setImage:BDFILEIMAGENAEM(@"Order/notChoose.png") forState:UIControlStateNormal];
            [self.cellContentView addSubview:self.takeButton];
            [self.takeButton addTarget:self action:@selector(take) forControlEvents:UIControlEventTouchDown];
        }
        
        THUserInfoModel *userModel = [THMangerTool getAccountInfo];
       
        if([isPutInStorageString isEqualToString:@"1"] && ![userModel.userType isEqualToString:@"1"]) {

            self.takeButton = [RZCustomButtom buttonWithType:UIButtonTypeCustom];
            [self.takeButton setImage:BDFILEIMAGENAEM(@"Order/choosing.png") forState:UIControlStateNormal];
            
            [self.takeButton setTitleColor:[UtilCheck hexStringToColor:@"2196f3" alpha:1] forState:(UIControlStateNormal)];
            [self.takeButton setTitle:[THMangerTool language:@"orderDetail.return"] forState:(UIControlStateNormal)];
            self.takeButton.titleLabel.font = CustomFont(10);
            [self.cellContentView addSubview:self.takeButton];
        }
        if ([[_orderStatusDict objectForKey:@"type"] integerValue ] == 1) {//备件管理
            self.type = 1;
        }else{//备件替换
            self.type = 2;
        }
        if ([[orderStatusDict objectForKey:@"type"] integerValue] != 1 ) {
            self.promptBtn.hidden = YES;
        }
        if ([[orderStatusDict objectForKey:@"type"] integerValue] == 2) {
            self.snLab.hidden = YES;
        }
    }
}

// 取件按钮点击
- (void)take{
    
    NSLog(@"点击的是%ld",self.row);
    
    
    if (state == 0) {
        [self.takeButton setImage:BDFILEIMAGENAEM(@"Order/choosing.png") forState:UIControlStateNormal];
        state = 1;
    }else if (state == 1){
        [self.takeButton setImage:BDFILEIMAGENAEM(@"Order/notChoose.png") forState:UIControlStateNormal];
        state = 0;
    }
    
    if (self.takeBlock) {
        self.takeBlock(state);
    }

}


- (void)layoutSubviews {
    TICK
    [self setUpCellDataAndView];
    TOCK
}

//计算cell高度
-(CGFloat)createStepView{

    [self setUpCellDataAndView];
    CGFloat height = self.separateLab.bottom ;
    
    NSLog(@"分割线的位置是2-----%f",height);
    return  height;

}

//根据数据将view加到cell上面去
- (void)setUpCellDataAndView{
    [self.cellContentView setFrame:CGRectMake(0, 0, self.width, self.height)];
    
    
    CGFloat width= self.width;
    CGFloat halfWidth = width/2 + 20;
    
    if (self.index == 0) {
        //故障件
        [self.NumOfGoodsLab setFrame:CGRectMake(LEFTEMARGIN, TOPMARGIN, self.width, LABHEIGHT)];
        self.NumOfGoodsLab.text = [NSString stringWithFormat:@"%@%@  %@%@",[THMangerTool language:@"Order.FaultyQty"],[_data objectForKey:@"faultPartNum"],[THMangerTool language:@"Order.OnSiteSpareQty"],[_data objectForKey:@"oneLinePartNum"]];
    
        [self.NumOfGoodsLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[THMangerTool language:@"Order.FaultyQty"],@"key",[THMangerTool language:@"Order.OnSiteSpareQty"],@"key2",nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"000000" alpha:1],NSForegroundColorAttributeName, nil],@"key",[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"000000" alpha:1],NSForegroundColorAttributeName, nil],@"key2",nil]];
        [self.NumOfGoodsLab sizeToFit];
        if(self.NumOfGoodsLab.height<LABHEIGHT){
            self.NumOfGoodsLab.height=LABHEIGHT;
        }
        
        //收到好件时间
        if ([_data objectForKey:@"receiveGoodPartTime"]!=nil) {
            self.receiveGoodPartTime=[[RZCustomLable alloc]init];
            self.receiveGoodPartTime.font = CustomFont(12);
            self.receiveGoodPartTime.text = [NSString stringWithFormat:@"收到好件时间：%@",[_data objectForKey:@"receiveGoodPartTime"]];
            self.receiveGoodPartTime.textColor=[UtilCheck hexStringToColor:@"999999" alpha:1];
            self.receiveGoodPartTime.textAlignment = NSTextAlignmentLeft;
            [self.cellContentView addSubview:self.receiveGoodPartTime];
            [self.receiveGoodPartTime setFrame:CGRectMake(halfWidth, TOPMARGIN, halfWidth, LABHEIGHT)];
            [self.receiveGoodPartTime sizeToFit];
            if(self.receiveGoodPartTime.height<LABHEIGHT){
                self.receiveGoodPartTime.height=LABHEIGHT;
            }
        }
        
        if (self.type == 2) {
            self.NumOfGoodsLab.text = [NSString stringWithFormat:@"%@:%@",[UtilCheck language:@"Order.FaultyUnitQty"],[_data objectForKey:@"faultPartNum"]];
        }
        
    }
    else{
        [self.NumOfGoodsLab setFrame:CGRectZero];
    }
    
    
    //序号
    [self.NumLab setFrame:CGRectMake(LEFTEMARGIN, TOPMARGIN + self.NumOfGoodsLab.bottom, LABHEIGHT, LABHEIGHT)];
    self.NumLab.text = [NSString stringWithFormat:@"%ld",self.index +1];
    [self.NumLab sizeToFit];
    if(self.NumLab.height<LABHEIGHT){
        self.NumLab.height=LABHEIGHT;
        self.NumLab.width=LABHEIGHT;
    }
    
    NSMutableArray *dataArray = [[NSMutableArray alloc]initWithArray: [_data objectForKey:@"faultParts"]];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithDictionary:dataArray[self.index]];
    
    
    NSMutableDictionary *faultPartDict = [[NSMutableDictionary alloc]initWithDictionary:[dict objectForKey:@"faultPart"]];
    
    NSMutableDictionary *goodPartDict = [[NSMutableDictionary alloc]init];
    if ([[dict objectForKey:@"goodPart"] isKindOfClass:[NSDictionary class]]) {
        goodPartDict = [[NSMutableDictionary alloc]initWithDictionary:[dict objectForKey:@"goodPart"]];
    }else {
        goodPartDict = nil;
    }
    
    //故障件信息
    [self.titleLabel setFrame:CGRectMake(self.NumLab.right + TOPMARGIN, TOPMARGIN + self.NumOfGoodsLab.bottom, self.width, LABHEIGHT)];
    self.titleLabel.text = [UtilCheck language:@"Order.FaultyUnitInfo"];
    [self.titleLabel sizeToFit];
    if(self.titleLabel.height<LABHEIGHT){
        self.titleLabel.height=LABHEIGHT;
    }
    
    [self.takeButton setFrame:CGRectMake(self.titleLabel.right + TOPMARGIN, TOPMARGIN + self.NumOfGoodsLab.bottom, 48, LABHEIGHT)];

    
    //RMA
    [self.RMALab setFrame:CGRectMake(LEFTEMARGIN,self.titleLabel.bottom, halfWidth - 20, LABHEIGHT)];
    
    NSString *RMAText = @"";
    if ([[NSString stringWithFormat:@"%@",[faultPartDict objectForKey:@"rma"]]isEqualToString:@"1"]) {
        RMAText = [THMangerTool language:@"Order.ViewDetail"];
        self.RMALab.hideText = [faultPartDict objectForKey:@"plateID"];
        self.RMALab.textColor = [UIColor blueColor];

    }else{
        RMAText = [NSString stringWithFormat:@"%@",[faultPartDict objectForKey:@"rma"]];
    }
    
    self.RMALab.text = [NSString stringWithFormat:@"RMA:%@",RMAText];
    [self.RMALab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:@"RMA:",@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
    
    
    self.RMALab.numberOfLines = 0;
    [self.RMALab sizeToFit];
    if(self.RMALab.height<LABHEIGHT){
        self.RMALab.height=LABHEIGHT;
    }
    
    UITapGestureRecognizer *RMAlabelTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(RMAlabelTouchUpInside:)];
    self.RMALab.userInteractionEnabled = YES;
    [self.RMALab addGestureRecognizer:RMAlabelTapGestureRecognizer];

    
    
    
    
    //板件名称
    [self.nameLab setFrame:CGRectMake(LEFTEMARGIN,  self.RMALab.bottom, halfWidth - 20, LABHEIGHT)];
    
    self.nameLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateName"],[faultPartDict objectForKey:@"plateName"]];
    [self.nameLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateName"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
    [self.nameLab sizeToFit];
    
    self.nameLab.left=LEFTEMARGIN;
    if(self.nameLab.height<LABHEIGHT){
        self.nameLab.height=LABHEIGHT;
    }
    
    //版件号
    [ self.codeLab setFrame:CGRectMake(LEFTEMARGIN, self.nameLab.bottom, width,LABHEIGHT)];
    self.codeLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateNO"],[faultPartDict objectForKey:@"plateCode"]];
    [self.codeLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateNO"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
    [self.codeLab sizeToFit];
    if(self.codeLab.height<LABHEIGHT){
        self.codeLab.height=LABHEIGHT;
    }
    //提示
    [self.promptBtn setFrame:CGRectMake(LEFTEMARGIN * 2 + self.codeLab.width, self.nameLab.bottom, halfWidth - LEFTEMARGIN * 5 - self.codeLab.width, LABHEIGHT)];
    [self.promptBtn sizeToFit];
    [self.promptBtn setTitle:[NSString stringWithFormat:@"还剩%@件",[faultPartDict objectForKey:@"remaining"]] forState:UIControlStateNormal];
    if ([[faultPartDict objectForKey:@"remaining"] integerValue] == 0) {
        [self.promptBtn setBackgroundImage:BDFILEIMAGENAEM(@"Order/orderDetailPromptRed") forState:UIControlStateNormal];
    }
    if (![faultPartDict objectForKey:@"remaining"] || [[faultPartDict objectForKey:@"remaining"] length] == 0) {
        [self.promptBtn removeFromSuperview];
    }
    //暂时移除，需求变动
    [self.promptBtn removeFromSuperview];
    
    
    //版本号
    [self.vsLab setFrame:CGRectMake(LEFTEMARGIN, self.codeLab.bottom, width,LABHEIGHT)];
    self.vsLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateCode"],[faultPartDict objectForKey:@"plateVersion"]];
    [self.vsLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateCode"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
    
    [self.vsLab sizeToFit];
    self.vsLab.left=LEFTEMARGIN;
    if(self.vsLab.height<LABHEIGHT){
        self.vsLab.height=LABHEIGHT;
    }
    
    //序列号
    [self.snLab setFrame:CGRectMake(LEFTEMARGIN, self.vsLab.bottom, width,LABHEIGHT)];
    self.snLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateSerial"],[faultPartDict objectForKey:@"plateSn"]];
    [self.snLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateSerial"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
    [self.snLab sizeToFit];
    if(self.snLab.height<LABHEIGHT){
        self.snLab.height=LABHEIGHT;
    }
    
    
    if (self.type == 2) {
        [self.snLab setHeight:0.0f];
    }
    
    
    //数量
    [self.countLab setFrame:CGRectMake(LEFTEMARGIN, self.snLab.bottom, width,LABHEIGHT)];
    self.countLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"order.count"],[faultPartDict objectForKey:@"number"]];
    [self.countLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"order.count"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
    [self.countLab sizeToFit];
    if(self.countLab.height<LABHEIGHT){
        self.countLab.height=LABHEIGHT;
    }
    
    
    
    
    
    
    //故障描述
    
    [self.troubleDescribleLab setFrame:CGRectMake(LEFTEMARGIN, self.countLab.bottom , halfWidth - 30,LABHEIGHT)];
    self.troubleDescribleLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"seeting.troubleDescribe"],[dict objectForKey:@"detail"]];
    [self.troubleDescribleLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"seeting.troubleDescribe"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
    self.troubleDescribleLab.hideText = [dict objectForKey:@"detail"];

    [self.troubleDescribleLab sizeToFit];
    if(self.troubleDescribleLab.height<LABHEIGHT){
        self.troubleDescribleLab.height=LABHEIGHT;
    }
    
    
    UITapGestureRecognizer *labelTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(labelTouchUpInside:)];
    self.troubleDescribleLab.userInteractionEnabled = YES;
    [self.troubleDescribleLab addGestureRecognizer:labelTapGestureRecognizer];
    
    //站名
    [self.stationNameLab setFrame:CGRectMake(LEFTEMARGIN, self.troubleDescribleLab.bottom, width,LABHEIGHT)];
    self.stationNameLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"seeting.stationName"],[faultPartDict objectForKey:@"stationName"]];
    [self.stationNameLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"seeting.stationName"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
    [self.stationNameLab sizeToFit];
    if(self.stationNameLab.height<LABHEIGHT){
        self.stationNameLab.height=LABHEIGHT;
    }
    
    if (self.type == 2) {
        [self.stationNameLab setHeight:0.0f];
        
    }
    
    //siteID
    [self.siteIDLab setFrame:CGRectMake(LEFTEMARGIN, self.stationNameLab.bottom, width,LABHEIGHT)];
    self.siteIDLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"siteID"],[faultPartDict objectForKey:@"siteID"]];
    [self.siteIDLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"siteID"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
    [self.siteIDLab sizeToFit];
    if(self.siteIDLab.height<LABHEIGHT){
        self.siteIDLab.height=LABHEIGHT;
    }
    
    if (self.type == 2) {
        [self.siteIDLab setHeight:0.0f];
        
    }
    
   
    //好件
    if (goodPartDict != nil) {
        // 好件信息
        [self.goodTitleLab setFrame:CGRectMake(halfWidth, TOPMARGIN + self.NumOfGoodsLab.bottom, self.width, LABHEIGHT)];
        self.goodTitleLab.text = [UtilCheck language:@"Order.SWAPUnitInfo"];
        [self.goodTitleLab sizeToFit];
        if(self.goodTitleLab.height<LABHEIGHT){
            self.goodTitleLab.height=LABHEIGHT;
        }
        
        
        
        
        //板件名称
        [self.goodNameLab setFrame:CGRectMake(halfWidth,  self.goodTitleLab.bottom, halfWidth -40, LABHEIGHT)];
        
        self.goodNameLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateName"],[goodPartDict objectForKey:@"goodPartName"]];
        [self.goodNameLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateName"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
        [self.goodNameLab sizeToFit];
        
        if(self.goodNameLab.height<LABHEIGHT){
            self.goodNameLab.height=LABHEIGHT;
        }
        
        //版件号
        [ self.goodCodeLab setFrame:CGRectMake(halfWidth, self.goodNameLab.bottom, halfWidth - 40,LABHEIGHT)];
        self.goodCodeLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateNO"],[goodPartDict objectForKey:@"goodPartCode"]];
        [self.goodCodeLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateNO"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
        [self.goodCodeLab sizeToFit];
        if(self.goodCodeLab.height<LABHEIGHT){
            self.goodCodeLab.height=LABHEIGHT;
        }
        
        //版本号
        [self.goodVsLab setFrame:CGRectMake(halfWidth, self.goodCodeLab.bottom, halfWidth/2,LABHEIGHT)];
        self.goodVsLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateCode"],[goodPartDict objectForKey:@"goodPartVersion"]];
        [self.goodVsLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateCode"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
        [self.goodVsLab sizeToFit];
        if(self.goodVsLab.height<LABHEIGHT){
            self.goodVsLab.height=LABHEIGHT;
        }
        
        //好件数量
        [self.goodNumber setFrame:CGRectMake(halfWidth, self.goodVsLab.bottom, halfWidth, LABHEIGHT)];
        self.goodNumber.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"seeting.number"],[faultPartDict objectForKey:@"number"]];
        [self.goodNumber textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"seeting.number"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
        [self.goodNumber sizeToFit];
        if (self.goodNumber.height<LABHEIGHT) {
            self.goodNumber.height=LABHEIGHT;
        }
        
        //序列号
        [self.goodSnLab setFrame:CGRectMake(halfWidth, self.goodNumber.bottom, halfWidth - 40,LABHEIGHT)];
        self.goodSnLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateSerial"],[goodPartDict objectForKey:@"goodPartSn"]];
        [self.goodSnLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateSerial"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
        [self.goodSnLab sizeToFit];
        if(self.goodSnLab.height<LABHEIGHT){
            self.goodSnLab.height=LABHEIGHT;
        }
        
        [self.uprightSeparateLab setFrame:CGRectMake(halfWidth - 15, self.goodTitleLab.top, 0.5, self.goodSnLab.bottom - self.goodTitleLab.top )];
        
        
        
    }
    
    if (self.goodSnLab.bottom > self.siteIDLab.bottom) {
        [self.separateLab setFrame:CGRectMake(LEFTEMARGIN, self.goodSnLab.bottom + TOPMARGIN, self.width - LEFTEMARGIN * 2, 0.5)];
    }else{
        [self.separateLab setFrame:CGRectMake(LEFTEMARGIN, self.siteIDLab.bottom + TOPMARGIN, self.width - LEFTEMARGIN * 2, 0.5)];
    
    }
    
    
    //一线备件
    if ([[dict objectForKey:@"isUseOneLine"] isEqualToString:@"是"]) {
        NSMutableDictionary *oneLineInfoDcit = [dict objectForKey:@"oneLineInfo"];
        
        //一线备件标题
        [self.subTitleLab setFrame:CGRectMake(LEFTEMARGIN, self.siteIDLab.bottom +TOPMARGIN, width, LABHEIGHT)];
        self.subTitleLab.text = [THMangerTool language:@"MyOrder.UsedOnsiteSpares"]; //@"使用了一线备件";
        [self.subTitleLab sizeToFit];
        if(self.subTitleLab.height<LABHEIGHT){
            self.subTitleLab.height=LABHEIGHT;
        }
        
        //板件名称
        [self.subNameLab setFrame:CGRectMake(LEFTEMARGIN, TOPMARGIN + self.subTitleLab.bottom, width, LABHEIGHT)];
        
        self.subNameLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateName"],[oneLineInfoDcit objectForKey:@"oneLineName"]];
        [self.subNameLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateName"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
        [self.subNameLab sizeToFit];
        
        self.subNameLab.left=LEFTEMARGIN;
        if(self.subNameLab.height<LABHEIGHT){
            self.subNameLab.height=LABHEIGHT;
        }
        
        //板件号
        [self.subCodeLab setFrame:CGRectMake(LEFTEMARGIN, TOPMARGIN + self.subNameLab.bottom, width, LABHEIGHT)];
        
        self.subCodeLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateNO"],[oneLineInfoDcit objectForKey:@"oneLineCode"]];
        [self.subCodeLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateNO"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
        [self.subCodeLab sizeToFit];
        
        self.subCodeLab.left=LEFTEMARGIN;
        if(self.subCodeLab.height<LABHEIGHT){
            self.subCodeLab.height=LABHEIGHT;
        }
        
        //板件版本号
        [self.subVsLab setFrame:CGRectMake(LEFTEMARGIN, TOPMARGIN + self.subCodeLab.bottom, width, LABHEIGHT)];
        
        self.subVsLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateCode"],[oneLineInfoDcit objectForKey:@"oneLineVersion"]];
        [self.subVsLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateCode"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
        [self.subVsLab sizeToFit];
        
        self.subVsLab.left=LEFTEMARGIN;
        if(self.subVsLab.height<LABHEIGHT){
            self.subVsLab.height=LABHEIGHT;
        }
        
        //序列号
        [self.subSnLab setFrame:CGRectMake(LEFTEMARGIN, self.subVsLab.bottom + TOPMARGIN, width,LABHEIGHT)];
        self.subSnLab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateSerial"],[oneLineInfoDcit objectForKey:@"oneLineSN"]];
        [self.subSnLab textAttributedKey:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%@:",[THMangerTool language:@"setting.plateSerial"]],@"key", nil] AttributedValue:[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:[UtilCheck hexStringToColor:@"999999" alpha:1],NSForegroundColorAttributeName, nil],@"key", nil]];
        [self.subSnLab sizeToFit];
        if(self.subSnLab.height<LABHEIGHT){
            self.subSnLab.height=LABHEIGHT;
        }
        
        
        [self.separateLab setFrame:CGRectMake(LEFTEMARGIN, self.subSnLab.bottom + TOPMARGIN, self.width - LEFTEMARGIN * 2, 0.5)];
        
        
    }
    else{
        self.subTitleLab.hidden=YES;
        self.subNameLab.hidden=YES;
    }
    

}

-(void) labelTouchUpInside:(UITapGestureRecognizer *)recognizer{
    
     HideTextLable *label=(HideTextLable*)recognizer.view;
    if (self.touchBlock) {
        self.touchBlock(label.text);
    }
}

-(void) RMAlabelTouchUpInside:(UITapGestureRecognizer *)recognizer{
    
    HideTextLable *label=(HideTextLable*)recognizer.view;
    if (self.RMATouchBlock) {
        self.RMATouchBlock(label.hideText);
    }
}



- (void)describleLableClick:(DetailTouchBlock)block{
    if (self) {
        self.touchBlock = block;
    }
}

- (void)RMALableClick:(RMADetailTouchBlock)block{
    if (self) {
        self.RMATouchBlock = block;
    }
}


@end
